package com.ssyc.gsk_teacher.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.ssyc.common.glide.ImageUtil;
import com.ssyc.gsk_teacher.R;
import com.ssyc.gsk_teacher.bean.StudentAnalyInfo;

import java.util.List;

/**
 * 学生分析适配器
 * Created by Administrator on 2018/7/2 0002.
 */

public class StudentAnalyRvAdapter extends BaseQuickAdapter<StudentAnalyInfo.DataBean, BaseViewHolder> {

    private Context context;
    private onDetailsClickListener listener;

    public StudentAnalyRvAdapter(Context context, int layoutResId, @Nullable List<StudentAnalyInfo.DataBean> data) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, StudentAnalyInfo.DataBean item) {

        //显示1,2,3位的图标标记,只有条目位置在123时显示
        ImageView ivShowPos = helper.getView(R.id.iv_show_pos);


        //其它位置的文字标识
        TextView tvShowPos = helper.getView(R.id.tv_show_pos);

        if (helper.getLayoutPosition() == 1) {
            ivShowPos.setVisibility(View.VISIBLE);
            tvShowPos.setVisibility(View.GONE);
            ivShowPos.setImageResource(R.drawable.teacher_one);
        } else if (helper.getLayoutPosition() == 2) {
            ivShowPos.setVisibility(View.VISIBLE);
            tvShowPos.setVisibility(View.GONE);
            ivShowPos.setImageResource(R.drawable.teacher_two);
        } else if (helper.getLayoutPosition() == 3) {
            ivShowPos.setVisibility(View.VISIBLE);
            tvShowPos.setVisibility(View.GONE);
            ivShowPos.setImageResource(R.drawable.teacher_three);
        } else {
            ivShowPos.setVisibility(View.GONE);
            tvShowPos.setVisibility(View.VISIBLE);
            tvShowPos.setText((helper.getLayoutPosition() + 1) + "");
        }

        //头像
        RoundedImageView ivHead = helper.getView(R.id.iv_head);
        ImageUtil.displayImage(context, ivHead, item.getIcon());

        //姓名
        TextView tvName = helper.getView(R.id.tv_name);
        tvName.setText(item.getName());

        //百分比
        TextView tvPresent = helper.getView(R.id.tv_present);
        tvPresent.setText(item.getPercent());

        //详情
        Button btDetails = helper.getView(R.id.bt_details);
        btDetails.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(listener!=null){
                    listener.onDetailsClick(item);
                }
            }
        });

    }

    public void setListener(onDetailsClickListener listener) {
        this.listener = listener;
    }

    public interface onDetailsClickListener {
        void onDetailsClick(StudentAnalyInfo.DataBean item);
    }
}
